const formatRichText = richText => {
    if (richText != null) {
        let newRichText = richText.replace(/<img[^>]*>/gi, match => {
            let newMactch = match
            newMactch = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
            newMactch = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
            newMactch = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
            return newMactch
        })
        newRichText = newRichText.replace(/style="[^"]+"/gi, match => {
            let newMactch = match
            newMactch = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;')
            return newMactch
        })
        newRichText = newRichText.replace(/<br[^>]*\/>/gi, '')
        newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"')
        return newRichText
    } else {
        return null
    }
}

export default formatRichText
